package com.vue.vuedemo.Controller;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.vue.vuedemo.pojo.Persons;
import com.vue.vuedemo.pojo.Team;
import com.vue.vuedemo.service.TeamService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@JsonIgnoreProperties({"hibernateLazyInitializer","handler"})
@CrossOrigin(origins = {"http://localhost:8080"}) //当前网站向另一个网站请求数据就是跨域
@Controller
public class TeamController {

    @Resource
    TeamService teamService;

    //展示厂商
    @GetMapping(value="TeamFindAll")
    public List<Team> findAll(){
        List<Team> teamList = teamService.findAll();
        return teamList;
    }

    //添加厂商
    @PostMapping(value = "TeamAdd")
    @ResponseBody
    public Integer add(@RequestBody Team team){
        System.out.print(team.getTName());
            try {
                teamService.add(team);
                num = 1; //成功
            }catch (Exception ex){
                num = 2; //失败
            }
        return num;
    }

    public Integer num;
    //删除厂商
    @GetMapping(value = "TeamDel")
    public Integer teamDel(Integer tid){
        try {
            teamService.del(tid);
            num = 1; //成功
        }catch (Exception ex){
            num = 2; //失败
        }
        return num;
    }
}
